#include "stdafx.h"
#include "Entity.h"

namespace Be
{
	Entity::Entity(std::wstring p_Name)
		: m_Name(p_Name)
	{
	}

	Entity::~Entity()
	{
		std::set<Node*>::iterator l_Iter = m_NodeSet.begin();
		while(l_Iter != m_NodeSet.end())
		{
			std::set<Node*>::iterator l_CurIter = l_Iter;
			++l_Iter;

			Node* l_pNode = *l_CurIter;
			assert(l_pNode != 0);

			l_pNode->Invalid();
		}

		m_NodeSet.clear();
	}

	const std::wstring& Entity::GetName()
	{
		return m_Name;
	}

	void Entity::AddNode(Node* p_pNode)
	{
		assert(p_pNode != 0);
		assert(m_NodeSet.find(p_pNode) == m_NodeSet.end());

		m_NodeSet.insert(p_pNode);
	}

	void Entity::RemoveNode(Node* p_pNode)
	{
		assert(p_pNode != 0);

		std::set<Node*>::iterator l_Iter = m_NodeSet.find(p_pNode);
		assert(l_Iter != m_NodeSet.end());

		m_NodeSet.erase(l_Iter);
	}
}